package com.hang.gymmanager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hang.gymmanager.common.BasePageReq;
import com.hang.gymmanager.common.Response;
import com.hang.gymmanager.entity.InformEntity;
import com.hang.gymmanager.req.AddInformReq;
import com.hang.gymmanager.req.UpdateInformReq;
import com.hang.gymmanager.service.InformService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 通知控制器
 * @author wyq
 * @version v1.0.0
 * @explain
 * @date 2024/4/1 15:29
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/inform")
@CrossOrigin
public class InformController {

    private final InformService informService;

    /**
     * 通知列表
     * @param req
     * @return
     */
    @PostMapping("/page")
    public Response<Page<InformEntity>> all(@RequestBody BasePageReq req){
        Page<InformEntity> entities = informService.all(req);
        return Response.success(entities);
    }

    /**
     * 通知详情
     * @param informId
     * @return
     */
    @GetMapping("/detail/{informId}")
    public Response<InformEntity> detail(@PathVariable Integer informId){
        InformEntity entities = informService.detail(informId);
        return Response.success(entities);
    }

    /**
     * 添加通知
     * @param req
     * @return
     */
    @PostMapping("/add")
    public Response<Integer> add(@RequestBody AddInformReq req){
        Integer id = informService.add(req);
        return Response.success(id);
    }

    /**
     * 更新通知
     * @param req
     * @return
     */
    @PostMapping("/update")
    public Response update(@RequestBody UpdateInformReq req){
        informService.update(req);
        return Response.success();
    }

    /**
     * 通知详情
     * @param informId
     * @return
     */
    @GetMapping("/delete/{informId}")
    public Response delete(@PathVariable Integer informId){
        informService.delete(informId);
        return Response.success();
    }

}
